Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for false fragment #12

Closed
wants to merge 1 commit into from

Conversation

RedHatter
Copy link

If svelte is ran with dev mode off component.$$.fragment is false. This causes hmr to crash do to attempting to access component.$$.fragment.m. The fix is simple enough, just check for false before accessing.

This fixes #9.

@rixo
Copy link
Collaborator

rixo commented May 24, 2020

Hey 👋 Thanks for taking the time to look into this. I was a bit stuck on #9 that I had failed to reproduce, so I'm glad if we can get rid of it!

So, piecing all this together... component.$$.fragment is false when dev mode is off and the component is empty, right?

But... Since $capture_state, HMR doesn't work at all when dev mode is off. So, with this fix, we're effectively just silently disabling HMR, aren't we? All while keeping all the transform overhead it does to your code.

My understanding of the situation is there is something wrong if people have HMR on and dev mode off. Either they are building for prod and don't want HMR, or they want HMR but that means they should be in dev mode.

If I'm correct, I think the fix should happen higher up the chain, at bundler plugins level, where we can prevent any useless transform. I wonder if HMR should be considered a part of dev mode and so be silently disabled when dev mode is off (totally disabled, with no effect or code transform at all), or if we should disable with a warning, or just crash with an explicit error message. I like the first solution but I'm afraid it might cause plenty of "HMR just doesn't nothing at all" situations...

Maybe the options should be changed to something like the following, that would prevent any possibility of having HMR on and dev mode off?

svelte({
  dev: {
    hot: { ... }
  },
})

In any event, if the problem descend down into svelte-hmr, I don't think ignoring it at this point is the right solution. I'd just go with throwing an error, maybe whining that it is maybe about dev mode.

What do you think?

@RedHatter
Copy link
Author

RedHatter commented May 25, 2020

But... Since $capture_state, HMR doesn't work at all when dev mode is off. So, with this fix, we're effectively just silently disabling HMR, aren't we?

I hadn't though of this and was rather confused by it for a bit as hmr was still working in the svelte native template even with dev mode off. Turns out it was using an old version ([email protected]) that I assume pre-dates $capture_state. When I upgraded hmr indeed stopped working outside of dev mode.

If I'm correct, I think the fix should happen higher up the chain, at bundler plugins level, where we can prevent any useless transform. I wonder if HMR should be considered a part of dev mode and so be silently disabled when dev mode is off (totally disabled, with no effect or code transform at all), or if we should disable with a warning, or just crash with an explicit error message. I like the first solution but I'm afraid it might cause plenty of "HMR just doesn't nothing at all" situations...

I think the best approach here is early bailout with a warning. It makes sense for svelte-hmr to check for what needs to correctly run before running. Also at the same time if it can't run it should tell the user why (dev mode is disabled) so they can fix it.

I don't like crashing with an error message. hmr not working shouldn't halt the entire build.

Maybe the options should be changed to something like the following, that would prevent any possibility of having HMR on and dev mode off?

svelte({
  dev: {
    hot: { ... }
  },
})

I dislike the idea of changing the svelte options. This would require either support from the svelte end or bundler plugins changing the options before passing them to svelte. I don't think either are a good idea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

native support breaks with empty components
2 participants